#
# @lc app=leetcode.cn id=290 lang=python3
#
# [290] 单词规律
#

# @lc code=start
class Solution:
    def wordPattern(self, pattern: str, str: str) -> bool:
        str_lst = str.split(' ')
        if len(pattern) != len(str_lst): return False
        hashMap = {}
        for index, c in enumerate(pattern):
            if c not in hashMap.keys():
                hashMap[c] = str_lst[index]
            else:
                if hashMap[c] != str_lst[index]:
                    return False
        return len(set(hashMap.values())) == len(set(hashMap.keys()))
        
# @lc code=end

